using Domain.Entities;
using Domain.Services;
using System;

namespace UserInterface.Admin
{
    public partial class NewGroup : System.Web.UI.Page
    {
        protected void NewGroupButton_Click(object sender, EventArgs e)
        {
            string name = GroupNameTextBox.Text;
            string prefix = PrefixTextBox.Text;
            string suffix = SuffixTextBox.Text;
            bool canViewActiveUserlist = Convert.ToBoolean(CanViewActiveUserlistRadioButtonList.SelectedValue);
            bool canViewUserlist = Convert.ToBoolean(CanViewUserlistRadioButtonList.SelectedValue);
            bool canViewProfiles = Convert.ToBoolean(CanViewProfilesRadioButtonList.SelectedValue);
            bool canUseSearch = Convert.ToBoolean(CanUseSearchRadioButtonList.SelectedValue);
            bool isAdministratorGroup = Convert.ToBoolean(IsAdministratorGroupRadioButtonList.SelectedValue);

            Group newGroup = GroupService.NewGroup
            (
                name,
                prefix,
                suffix,
                canViewActiveUserlist,
                canViewUserlist,
                canViewProfiles,
                canUseSearch,
                isAdministratorGroup
            );

            
            if (newGroup != null)
            {
                Response.Redirect("EditGroup.aspx?messageId=" + newGroup.Id);
            }
            else
            {
                BoardAdmin masterPage = Master as BoardAdmin;
                masterPage.Messages.AddCritical(Resources.Resource.InvalidFormData);
            }
        }
    }
}
